using FineCollection.Intf;

using NUnit.Framework;




namespace FineCollection.Cont
{
    [TestFixture]
    public class HashMap_test
    {
        
        [Test]
        public void test_Count ()
        {
            WMap<char,long> map = new HashMap<char,long>();

            Assert.AreEqual(0, map.Count);

            map.Include('A', 3333333333333333333);
            Assert.AreEqual(1, map.Count);

            map.Include('B', 4444444444444444444);
            Assert.AreEqual(2, map.Count);

            map.Include('C', 5555555555555555555);
            Assert.AreEqual(3, map.Count);

            map.Exclude('A');
            Assert.AreEqual(2, map.Count);

            map.Exclude('C');
            Assert.AreEqual(1, map.Count);

            map.Exclude('B');
            Assert.AreEqual(0, map.Count);
        }


        [Test]
        public void test_Indexator_Basic()
        {
            WMap<char,long> map = new HashMap<char, long>();

            map['A'] = 33L;
            map['B'] = 44L;

            Assert.AreEqual(33L, map['A']);
            Assert.AreEqual(44L, map['B']);
        }

        
        [Test]
        public void test_Indexator_Replace()
        {
            WMap<char,long> map = new HashMap<char, long>();

            map['A'] = 33L;
            map['B'] = 44L;
            map['C'] = 55L;

            Assert.AreEqual(44L, map['B']);

            map['B'] = 99L;

            Assert.AreEqual(99L, map['B']);
        }

        
        [Test]
        public void test_Indexator_SameHash()
        {
            WMap<long,long> map = new HashMap<long, long>();

            // we're assuming that the initial mod = 37
            map[1L] = 1111111111111L;
            map[38L] = 2222222222222L;

            Assert.AreEqual(1111111111111L, map[1L]);
            Assert.AreEqual(2222222222222L, map[38L]);
        }

        
        [Test]
        public void test_ContainsKey_Found()
        {
            WMap<char,long> map = new HashMap<char, long>();

            map['A'] = 33L;
            map['B'] = 44L;
            map['C'] = 55L;

            bool z = map.ContainsKey('B');
            Assert.IsTrue(z);
        }

        
        [Test]
        public void test_ContainsKey_NotFound()
        {
            WMap<char,long> map = new HashMap<char, long>();

            map['A'] = 33L;
            map['C'] = 55L;

            bool z = map.ContainsKey('B');
            Assert.IsFalse(z);
        }

        
        [Test]
        public void test_ContainsKey_NotFound_ButSameHash()
        {
            WMap<long,long> map = new HashMap<long, long>();

            // we're assuming that the initial mod = 37
            map[38L] = 777;

            bool z = map.ContainsKey(1L);
            Assert.IsFalse(z);
        }


        [Test]
        public void test_X_perf1()
        {
            const ushort N = 60000;

            // generating data
            long[] values = new long[N];
            for (int i = 0; i < N; i++)
                values[i] = ((long)(i+1)) << 32 + i*53;

            // filling
            WMap<ushort,long> map = new HashMap<ushort,long>();
            for (ushort i = 1; i <= N; i++)
                map[i] = values[i - 1];

            // testing
            for (ushort i = 1; i <= N; i++)
                Assert.AreEqual(values[i - 1], map[i]);
        }
        
    }
}